import axios from 'axios';
import useRequestInterceptor from './config/request';
import { useResponseInterceptor } from './config/response';

const { VITE_SERVER, VITE_API } = import.meta.env;

const service = axios.create({
  baseURL: `${VITE_SERVER}${VITE_API}`,
  timeout: 30000,
});

// Request interceptors
service.interceptors.request.use(useRequestInterceptor as any, (error: any) => {
  Promise.reject(error);
});

// Response interceptors
service.interceptors.response.use(
  useResponseInterceptor as any,
  useResponseInterceptor,
);

export function useRequest() {
  return service;
}
